$(() => {
  // 页面加载完成获取其他页面传递的参数
  var Request = new Object();
  Request = GetRequest();
  var price = Request["price"];
  $("#tiaozhuanprice").html(price);


  // 页面加载完成加载收货人信息
  (() => {
    var receiptInfo = {
      receiptName: localStorage.getItem("receiptName"),
      receiptPhone: localStorage.getItem("receiptPhone"),
      receiptAddress: localStorage.getItem("receiptAddress")
    };
    if (
      receiptInfo.receiptName &&
      receiptInfo.receiptPhone &&
      receiptInfo.receiptAddress
    ) {
      $("#shouhuoren").html(receiptInfo.receiptName + " /");
      $("#shphone").html(receiptInfo.receiptPhone);
      $("#shdi").html(receiptInfo.receiptAddress);
      $("#shid").val(localStorage.getItem("fid"));
    } else {
      $(".deliverbox,.rhoose,.active").hide();
      $("#lijibaoming").attr("disabled", "disabled");
    }
  })();
  // 关闭地址输入框
  $(".close").click(() => {
    clearform();
    $(".deliverJB,.opcy").hide();
  });

  // 清理表单
  function clearform() {
    $("#psname").val("");
    $("#wapsname").val("");
    $("#psphone").val("");
    $("#wapsphone").val("");
    $("#psaddress").val("");
    $("#wapsaddress").val("");
  }

  // 点击输入框取消提示信息
  $("#psname").focus(() => {
    hiddeninfo("wapsname");
  });
  $("#psphone").focus(() => {
    hiddeninfo("wapsphone");
  });
  $("#psaddress").focus(() => {
    hiddeninfo("wapsaddress");
  });

  // 获取用户输入的收货地址信息并存入localstorage
  $("#savemessage").click(() => {
    var addressData = {
      receiptName: $("#psname").val(),
      receiptPhone: $("#psphone").val(),
      receiptAddress: $("#psaddress").val()
    };
    if (addressData.receiptName == "") {
      waringinfo("wapsname", "psname", "请输入收货人姓名");

      return;
    }
    if (addressData.receiptPhone == "") {
      waringinfo("wapsphone", "psphone", "请输入收货人手机");

      return;
    }
    if (!isPoneAvailable(addressData.receiptPhone)) {
      waringinfo("wapsaddress", "psaddress", "手机号输入格式不正确");

      return;
    }
    if (addressData.receiptAddress == "") {
      waringinfo("wapsaddress", "请输入收货人地址");

      return;
    }

    let userinfo = ["receiptName", "receiptPhone", "receiptAddress"];
    userinfo.forEach(v => {
      localStorage[v] = addressData[v];
      clearform();
      $(".deliverJB,.opcy").hide();
      window.location.reload();
    });
  });

  // 点击报名
  $("#lijibaoming").click(() => {
    var bmdata = {
      fid: localStorage.getItem("fid"),
      price: price,
      title: "酷赚K1Plus",
      receiptName: localStorage.getItem("receiptName"),
      receiptPhone: localStorage.getItem("receiptPhone"),
      receiptAddress: localStorage.getItem("receiptAddress"),
      // 获取前一个页面的地址
      pageUrl: document.referrer.split("/").pop()
    };
    console.log(bmdata);

    $.post("http://121.43.172.175/api/order.html", bmdata, data => {
    // $.post("http://192.168.0.125:8081/api/order.html", bmdata, data => {
      if (data.status == 1) {
        fadetip(data.data.msg);
      } else {
        fadetip(data.data.msg);
      }
      console.log(data);
    });
  });
});
